package com.tyd.cams;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.tyd.cams.entity.JsInfoBean;

import java.util.List;

import static com.xuexiang.xui.utils.ResUtils.getColor;

/**
 * @author: TYD
 * @作者: 唐YaDong
 * @date: 2021/3/13 22:57
 * @description：JsRecyclerAdapter
 * @描述：JsRecyclerAdapter
 * @版本：1.0
 */
public class JsRecyclerAdapter extends RecyclerView.Adapter<JsRecyclerAdapter.ViewHplder> {
    Context context;
    List<JsInfoBean> jiaoXloubeans;
    LayoutInflater layoutInflater;

    public JsRecyclerAdapter(Context context, List<JsInfoBean> jiaoXloubeans) {
        this.context = context;
        this.jiaoXloubeans = jiaoXloubeans;
    }

    @NonNull
    @Override
    public ViewHplder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = layoutInflater.from(parent.getContext()).inflate(R.layout.js_info, parent
                , false);
        return new ViewHplder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHplder holder, int position) {
        JsInfoBean jsInfoBean = jiaoXloubeans.get(position);
        holder.js_mc.setText(jsInfoBean.getJsname());
        holder.js_lx.setText(jsInfoBean.getJstype());
        if (jsInfoBean.getPknum() == 0) {
            holder.js_zt.setText("空教室：未排课");
            holder.js_zt.setTextColor(getColor(R.color.teal_200));
        } else {
            holder.js_zt.setTextColor(getColor(R.color.qmui_config_color_red));
            holder.js_zt.setText("有" + jsInfoBean.getPknum() + "节课");
        }
        switch (jsInfoBean.getJstype()) {
            case "标准教室":
                holder.js_icon.setImageResource(R.drawable.js_ptj);
                break;
            case "计算机教室":
                holder.js_icon.setImageResource(R.drawable.js_jsj);
                break;
            case "实验室":
                holder.js_icon.setImageResource(R.drawable.js_syans);
                break;
            case "图书馆":
                holder.js_icon.setImageResource(R.drawable.js_tsg);
                break;
            default:
                break;
        }

    }

    @Override
    public int getItemCount() {
        return jiaoXloubeans == null ? 0 : jiaoXloubeans.size();

    }

    public class ViewHplder extends RecyclerView.ViewHolder {
        private TextView js_mc;
        private TextView js_lx;
        private TextView js_zt;
        private ImageView js_icon;

        public ViewHplder(@NonNull View itemView) {
            super(itemView);
            js_mc = itemView.findViewById(R.id.js_mc);
            js_lx = itemView.findViewById(R.id.js_lx);
            js_zt = itemView.findViewById(R.id.js_zt);
            js_icon = itemView.findViewById(R.id.js_icon);
        }
    }
}
